<!DOCTYPE html>
<html>

<head lang="en">
    <meta charset="UTF-8">
    <title>登录</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <meta name="format-detection" content="telephone=no">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>

    <link rel="stylesheet" href="./AmazeUI-2.4.2/assets/css/amazeui.css"/>
    <link href="./css/dlstyle.css" rel="stylesheet" type="text/css">
    <script src="./AmazeUI-2.4.2/assets/js/jquery.min.js"></script>
    <script src="./AmazeUI-2.4.2/assets/js/amazeui.min.js"></script>

    <!-- 导入vuejs和axios -->
    <script src="./plugins/vue/dist/vue.js"></script>
    <script src="./plugins/axios/dist/axios.js"></script>
    <script src="./js/common.js"></script>
    <style type="text/css">
        .validateMsg{
            font-size: 12px;
            color: red;
        }
        #dyMobileButton:disabled {
            cursor: no-drop;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="login-boxtitle">
            <a href="home.html"><img alt="logo" src="./images/logobig.png"/></a>
        </div>

        <div class="login-banner">
            <div class="login-main">
                <div class="login-banner-bg"><span></span><img src="./images/big.jpg"/></div>
                <div class="login-box">
                    <div class="am-tabs" id="doc-my-tabs">
                        <ul class="am-tabs-nav am-nav am-nav-tabs am-nav-justify">
                            <li class="am-active"><a href="">密码登录</a></li>
                            <li><a href="">验证码登录</a></li>
                        </ul>
                        <div class="am-tabs-bd" style="margin-top: -20px;">
                            <!-- 密码登录 -->
                            <div class="am-tab-panel am-active">
                                <div class="login-form">
                                    <form :model="loginForm">
                                        <div class="user-name">
                                            <label for="user"><i class="am-icon-user"></i></label>
                                            <input type="text" v-model="loginForm.username" @blur="validateUsername" id="user" placeholder="邮箱/手机/用户名">
                                            <span class="validateMsg">{{usernameValidateMsg}}</span>
                                        </div>
                                        <div class="user-pass">
                                            <label for="password"><i class="am-icon-lock"></i></label>
                                            <input type="text" v-model="loginForm.password" @blur="validatePassword" id="password" placeholder="请输入密码">
                                            <span class="validateMsg">{{passwordValidateMsg}}</span>
                                        </div>
                                    </form>
                                </div>
                                <div class="login-links">
                                    <label for="remember-me"><input id="remember-me" type="checkbox">记住密码</label>
                                    <a href="#" class="am-fr">忘记密码</a>
                                    <a href="register.html" class="am-fr">注册&nbsp;</a>
                                    <br/>
                                </div>
                                <div class="am-cf">
                                    <input type="button" @click="login" value="登 录" class="am-btn am-btn-primary am-btn-sm">
                                    <br/>
                                    <span class="validateMsg" style="font-size: 16px;text-align: center;display: block;">{{loginErrorMsg}}</span>
                                </div>
                            </div>

                            <!-- 验证码登录 -->
                            <div class="am-tab-panel">
                                <div class="login-form">
                                    <form method="post" :model="phoneLogin">
                                        <div class="user-phone">
                                            <label for="phone"><i class="am-icon-mobile-phone am-icon-md"></i></label>
                                            <input type="tel" v-model="phoneLogin.phone" id="phone" placeholder="请输入手机号">
                                            <span class="validateMsg">{{phoneValidateMsg}}</span>
                                        </div>
                                        <div class="verification">
                                            <label for="code"><i class="am-icon-code-fork"></i></label>
                                            <input type="tel" v-model="phoneLogin.verifyCode" id="code" placeholder="请输入验证码">
                                            <button type="button" class="btn" @click="sendMobileCode" :disabled="btnDisabled" id="dyMobileButton">{{btnText}}</button>
                                            <br/>
                                            <span class="validateMsg">{{verifyCodeValidateMsg}}</span>
                                        </div>
                                    </form>
                                </div>
                                <div class="login-links">
                                    <a href="register.html" class="am-fr">注册</a>
                                    <br/>
                                </div>
                                <div class="am-cf">
                                    <input type="submit" name="" value="登 录" class="am-btn am-btn-primary am-btn-sm">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="partner">
                        <h3>合作账号</h3>
                        <div class="am-btn-group">
                            <li><a href="#"><i class="am-icon-qq am-icon-sm"></i><span>QQ登录</span></a></li>
                            <li><a href="#"><i class="am-icon-weibo am-icon-sm"></i><span>微博登录</span> </a></li>
                            <li><a href="javascript:void(0);" @click="wechatLogin"><i class="am-icon-weixin am-icon-sm"></i><span>微信登录</span> </a></li>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="footer ">
            <div class="footer-hd ">
                <p>
                    <a href="# ">恒望科技</a>
                    <b>|</b>
                    <a href="# ">商城首页</a>
                    <b>|</b>
                    <a href="# ">支付宝</a>
                    <b>|</b>
                    <a href="# ">物流</a>
                </p>
            </div>
            <div class="footer-bd ">
                <p>
                    <a href="# ">关于恒望</a>
                    <a href="# ">合作伙伴</a>
                    <a href="# ">联系我们</a>
                    <a href="# ">网站地图</a>
                    <em>© 2015-2025 Hengwang.com 版权所有.</em>
                </p>
            </div>
        </div>
    </div>
    <script type="text/javascript">
        $(function () {
            $('#doc-my-tabs').tabs();  //开启选项卡的功能
        })

        new Vue({
            el:"#app",
            data: {
                loginForm:{
                    username:'',
                    password:'',
                    type: 'front'   //type等于front表示前台普通用户登录，等于admin表示后台管理系统用户登录
                },
                usernameValidateMsg:'',         //用户名/手机/邮箱验证信息
                passwordValidateMsg:'',         //密码验证信息
                loginErrorMsg:'',               //登录失败的提示消息
                phoneLogin:{
                    verifyCode:'',
                    phone:''
                },
                btnText:'获取',
                btnDisabled:false,              //获取按钮禁用
                phoneValidateMsg:'',            //手机号验证信息
                verifyCodeValidateMsg:'',       //验证码验证信息
                //微信登录获取二维码页面的接口地址
                wechatUrl: 'https://open.weixin.qq.com/connect/qrconnect?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=snsapi_login&state=STATE#wechat_redirect',
                //微信APPID
                appid:'wxd853562a0548a7d0',
                //回调域名
                callbackDomain: 'bugtracker.itsource.cn'
            },
            methods:{
                validateUsername(){
                    if(!this.loginForm.username){
                        this.usernameValidateMsg = '用户名不能为空！'
                        $("#user").css('border','1px solid red').parent().css('color',"red")
                        return false;
                    }
                    this.usernameValidateMsg = ''
                    $("#user").css('border','1px solid green').parent().css('color',"green")
                    return true;
                },
                validatePassword(){
                    if(!this.loginForm.password){
                        this.passwordValidateMsg = '密码不能为空！'
                        $("#password").css('border','1px solid red').parent().css('color',"red")
                        return false;
                    }
                    this.passwordValidateMsg = ''
                    $("#password").css('border','1px solid green').parent().css('color',"green")
                    return true;
                },
                //获取手机验证码
                sendMobileCode(){

                },
                login(){
                    if(this.validateUsername() & this.validatePassword()){
                        this.$http.post("/lr/passwordLogin", this.loginForm).then(res => {
                            let {success, msg, data} = res.data
                            if(success){
                                //将userToken和loginUser存储到localStorage中
                                localStorage.setItem("userToken", data.userToken)
                                localStorage.setItem("loginUser", data.loginUser)
                                location.href = 'index.html'
                            }else{
                                this.loginErrorMsg = msg
                            }
                        })
                    }
                },
                //微信登录
                wechatLogin(){
                    this.wechatUrl = this.wechatUrl.replace("APPID", this.appid)
                        .replace("REDIRECT_URI", "http://"+this.callbackDomain+"/wechatLoginResult.html")
                    //发送请求
                    location.href = this.wechatUrl
                }
            }
        })
    </script>
</body>

</html>